import createPersistedState from 'vuex-persistedstate'

export default new Vuex.Store({
  state: {
    loadingInstance: '',
    user: {}
  },
  mutations: {
    FullLoading (state, payload) {
      // state.loadingInstance = Loading.service({ fullscreen: true })
    },
    setUser (state, user) {
      state.user = user
    }
  },
  actions: {
    CloseLoading ({
      commit,
      state
    }, payload) {
      state.loadingInstance.close && state.loadingInstance.close()
    },
    FullLoading ({ commit }, payload) {
      commit('FullLoading')
    },
    logout ({ commit }) {
      commit('setUser', null)
    },
    updateUser ({ commit }, user) {
      commit('setUser', user)
    },
  },
  plugins: [createPersistedState({
    key: 'driver',
    paths: ['user'],
    storage: window.sessionStorage
  })],
})
